package com.cskaoyan;

/**
 * @author stone
 * @date 2022/01/27 20:03
 */
public class JosephusDemo {

    public static void main(String[] args) {
        Node node1 = new Node("红");
        Node node2 = new Node("橙");
        Node node3 = new Node("黄");
        Node node4 = new Node("绿");
        Node node5 = new Node("青");
        Node node6 = new Node("蓝");
        Node node7 = new Node("紫");
        Node node8 = new Node("黑");
        Node node9 = new Node("白");

        node1.next = node2;
        node2.next = node3;
        node3.next = node4;
        node4.next = node5;
        node5.next = node6;
        node6.next = node7;
        node7.next = node8;
        node8.next = node9;
        node9.next = node1;

        Node remainNode = getRemainNode(node1);
        System.out.println(remainNode.value);
    }

    private static Node getRemainNode(Node head) {
        Node current = head;
        while (current !=current.next) {
            current = current.next;
            current.next = current.next.next;
            current = current.next;
        }
        return current;
    }
}
